package com.rabbit.eap.controller.system;

import com.rabbit.eap.framework.common.api.ApiResult;
import com.rabbit.eap.framework.common.controller.BaseController;
import com.rabbit.eap.framework.core.validator.groups.AddGroup;
import com.rabbit.eap.framework.core.validator.groups.UpdateGroup;
import com.rabbit.eap.framework.log.annotation.Module;
import com.rabbit.eap.framework.log.annotation.OperationLog;
import com.rabbit.eap.framework.log.enums.OperationLogType;
import com.rabbit.eap.system.dto.SysConfigDTO;
import com.rabbit.eap.system.entity.SysConfig;
import com.rabbit.eap.system.param.SysConfigPageParam;
import com.rabbit.eap.system.service.ISysConfigService;
import com.rabbit.eap.system.vo.SysConfigVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * @projectName: eap
 * @packageName: com.rabbit.eap.system.controller
 * @className: SysConfigController
 * @author： rabbit
 * @version： 1.0
 * @since： 2020/06/06 23:05:26
 * <p>Description:
 * 参数配置表 控制器
 * </p>

 */
@Slf4j
@RestController
@RequestMapping("/system/sysConfig")
@Module("system")
@Api(value = "参数配置表API", tags = {"参数配置表"})
public class SysConfigController extends BaseController {

    @Autowired
    private ISysConfigService sysConfigService;


    /**
     * @param sysConfigDTO:sysConfigDTO数据传输对象
     * @Description: 添加参数配置表
     * @methodName: saveSysConfig
     * @return: ApiResult.result(flag)
     * @date: 2020/06/06 23:05:26
     * @author: rabbit
     */
    @PostMapping("/saveSysConfig")
    @RequiresPermissions("sys:config:add")
    @OperationLog(name = "添加参数配置表", type = OperationLogType.ADD)
    @ApiOperation(value = "添加参数配置表", response = ApiResult.class)
    public ApiResult saveSysConfig(@Validated(AddGroup.class) @RequestBody SysConfigDTO sysConfigDTO) throws Exception {
        ApiResult apiResult = sysConfigService.saveSysConfig(sysConfigDTO);
        return apiResult;
    }

    /**
     * @param sysConfigDTO:sysConfigDTO数据传输对象
     * @Description: 修改参数配置表
     * @methodName: modifySysConfig
     * @return: ApiResult
     * @date: 2020/06/06 23:05:26
     * @author: rabbit
     */
    @PutMapping("/modifySysConfig")
    @RequiresPermissions("sys:config:edit")
    @OperationLog(name = "修改参数配置表", type = OperationLogType.UPDATE)
    @ApiOperation(value = "修改参数配置表", response = ApiResult.class)
    public ApiResult modifySysConfig(@Validated(UpdateGroup.class) @RequestBody SysConfigDTO sysConfigDTO) throws Exception {
        ApiResult apiResult = sysConfigService.modifySysConfig(sysConfigDTO);
        return apiResult;
    }

    /**
     * @param ids:id集合
     * @Description: 删除参数配置表
     * @methodName: removeSysConfig
     * @return: ApiResult
     * @date: 2020/06/06 23:05:26
     * @author: rabbit
     */
    @DeleteMapping("/removeSysConfig")
    @RequiresPermissions("sys:config:remove")
    @OperationLog(name = "删除参数配置表", type = OperationLogType.DELETE)
    @ApiOperation(value = "删除参数配置表", response = ApiResult.class)
    public ApiResult removeSysConfig(@RequestParam("ids") Long[] ids) throws Exception {
        ApiResult apiResult = sysConfigService.removeSysConfig(ids);
        return apiResult;
    }

    /**
     * @param id: id
     * @Description: 根据Id获取参数配置表详情
     * @methodName: getSysConfigInfo
     * @return: ApiResult
     * @date: 2020/06/06 23:05:26
     * @author: rabbit
     */
    @GetMapping("/getSysConfigInfo")
    @RequiresPermissions("sys:config:query")
    @OperationLog(name = "根据Id获取参数配置表详情", type = OperationLogType.INFO)
    @ApiOperation(value = "根据Id获取参数配置表详情", response = SysConfigVO.class)
    public ApiResult getSysConfigInfo(@RequestParam("id") Long id) throws Exception {
        ApiResult apiResult = sysConfigService.getSysConfigById(id);
        return apiResult;
    }

    /**
     * @param configKey: 参数键名
     * @Description: 根据参数键名查询参数值
     * @methodName: getSysConfigByKey
     * @return: ApiResult
     * @date: 2020/6/12 22:31
     * @author: rabbit
     */
    @GetMapping("/getSysConfigByKey")
    @RequiresPermissions("sys:config:query")
    @OperationLog(name = "根据参数键名查询参数值", type = OperationLogType.INFO)
    @ApiOperation(value = "根据参数键名查询参数值", response = SysConfigVO.class)
    public ApiResult getSysConfigByKey(@RequestParam("configKey") String configKey) throws Exception {
        SysConfig sysConfig = sysConfigService.getSysConfigByKey(configKey);
        return ApiResult.ok(sysConfig);
    }

    /**
     * @param sysConfigPageParam
     * @Description: 参数配置表分页列表
     * @methodName: getSysConfigPageList
     * @return: ApiResult
     * @date: 2020/06/06 23:05:26
     * @author: rabbit
     */
    @GetMapping("getSysConfigPageList")
    @RequiresPermissions("sys:config:list")
    @OperationLog(name = "参数配置表分页列表", type = OperationLogType.PAGE)
    @ApiOperation(value = "参数配置表分页列表", response = SysConfigVO.class)
    public ApiResult getSysConfigPageList(SysConfigPageParam sysConfigPageParam) throws Exception {
        ApiResult apiResult = sysConfigService.getSysConfigPageList(sysConfigPageParam);
        return apiResult;
    }

}

